package com.bdqn.servlet.admin;

import com.bdqn.entity.CheckWork;
import com.bdqn.entity.PageBean;
import com.bdqn.service.AdminService;
import com.bdqn.service.Impl.AdminServiceImpl;
import com.bdqn.util.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "AdminPageQueryServlet",urlPatterns = "/adminPageQuery")
public class AdminPageQueryServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String empId = request.getParameter("empId");
        String start = request.getParameter("start");
        String end = request.getParameter("end");
        String strdepId = request.getParameter("depId");
        int depId = 0;
        if(strdepId!=null && strdepId.length()>0){
            depId = Integer.parseInt(strdepId);
        }
        String strcurrentPage = request.getParameter("currentPage");
        int currentPage = 1;
        if(strcurrentPage!=null && strcurrentPage.length()>0 && !"null".equals(strcurrentPage)){
            currentPage = Integer.parseInt(strcurrentPage);
        }
        String strpageSize = request.getParameter("pageSize");
        int pageSize = 2;
        if(strpageSize!=null && strpageSize.length()>0 && !"null".equals(strpageSize)){
            pageSize = Integer.parseInt(strpageSize);
        }
        AdminService service = new AdminServiceImpl();
        PageBean<CheckWork> pb = service.FindPageQuery(currentPage,pageSize,empId,depId,start,end);

        //PageBean<CheckWork> pb = service.findAll(currentPage,pageSize);
        JSON.writeAsString(pb,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
